package Controller;

import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.Timer;

/**
 * @deprecated not used yet
 * @author Vince
 * source : http://stackoverflow.com/questions/4577424/distinguish-between-a-single-click-and-a-double-click-in-java
 */
public abstract class MouseAction extends MouseAdapter implements ActionListener {

	private final static int clickInterval = (Integer)Toolkit.getDefaultToolkit().
	        getDesktopProperty("awt.multiClickInterval");

	    MouseEvent lastEvent;
	    Timer timer;

	    public MouseAction()
	    {
	        this(clickInterval);
	    }

	    public MouseAction(int delay)
	    {
	        timer = new Timer( delay, this);
	    }

	    public void mouseClicked (MouseEvent e)
	    {
	    	if (e.getClickCount() > 2) return;

	        lastEvent = e;

	        if (timer.isRunning())
	        {
	            timer.stop();
	            doubleClick( lastEvent );
	        }
	        else
	        {
	            timer.restart();
	        }
	    }

	    public void actionPerformed(ActionEvent e)
	    {
	        timer.stop();
	        singleClick( lastEvent );
	    }

	    public abstract void singleClick(MouseEvent e);
	    
	    public abstract void doubleClick(MouseEvent e);
}
